<%--
  Created by IntelliJ IDEA.
  User: 李昭富
  Date: 2024/5/31
  Time: 16:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ page import = "java.sql.*" %>
<%@ include file = "jdbc.jsp" %>
<%
    Connection conn=getConnection();
//3、建立Statement对象，用来执行sql
    Statement stmt=conn.createStatement();
//4、生成sql
    String sql="select * from user";
//5、执行sql
    ResultSet rs=stmt.executeQuery(sql);
//6、处理结果
%>
<table border="1" width="50%">
    <tr>
        <th>id</th>
        <th>用户名</th>
        <th>昵称</th>
        <th>性别</th>
        <th>操作</th>
    </tr>

    <%
        while(rs.next()){
            int id=rs.getInt("id");
            String username=rs.getString("username");
            String nickname=rs.getString("nickname");
            int sex=rs.getInt("sex");
            String str_sex=(sex==1)?"男":"女";
    %>
    <tr>
        <td><%=id %></td>
        <td><%=username %></td>
        <td><%=nickname %></td>
        <td><%=str_sex %></td>
        <td>
            <a href="del.jsp?id=<%=id%>">删除</a>
            <a href="edit.jsp?id=<%=id%>">修改</a>
        </td>
    </tr>
    <%}
        closeDB(conn,stmt,rs);
    %>
</table>